<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
	<head>
		<title>C Memory Model</title>
<link href="../docs-assets/Breadcrumbs.css" rel="stylesheet" rev="stylesheet" type="text/css">
		<meta name="viewport" content="width=device-width initial-scale=1">
		<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
		<meta http-equiv="Content-Language" content="en-gb">

<link href="../docs-assets/Contents.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Progress.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Navigation.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Fonts.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Base.css" rel="stylesheet" rev="stylesheet" type="text/css">
<script>
function togglePopup(material_id) {
  var popup = document.getElementById(material_id);
  popup.classList.toggle("show");
}
</script>

<link href="../docs-assets/Popups.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Colours.css" rel="stylesheet" rev="stylesheet" type="text/css">
<link href="../docs-assets/Extracts-Colours.css" rel="stylesheet" rev="stylesheet" type="text/css">
		
	</head>
	<body class="commentary-font">
		<nav role="navigation">
		<h1><a href="../index.html"><img src="../docs-assets/Inform.png" height=72> </a></h1>
<ul><li><a href="../index.html">home</a></li>
</ul><h2>Compiler</h2><ul>
<li><a href="../structure.html">structure</a></li>
<li><a href="../inbuildn.html">inbuild</a></li>
<li><a href="../inform7n.html">inform7</a></li>
<li><a href="../intern.html">inter</a></li>
<li><a href="../services.html">services</a></li>
<li><a href="../secrets.html">secrets</a></li>
</ul><h2>Other Tools</h2><ul>
<li><a href="../inblorbn.html">inblorb</a></li>
<li><a href="../inform6.html">inform6</a></li>
<li><a href="../inpolicyn.html">inpolicy</a></li>
</ul><h2>Resources</h2><ul>
<li><a href="../extensions.html">extensions</a></li>
<li><a href="../kits.html">kits</a></li>
</ul><h2>Repository</h2><ul>
<li><a href="https://github.com/ganelson/inform"><img src="../docs-assets/github.png" height=0> github</a></li>
</ul><h2>Related Projects</h2><ul>
<li><a href="https://github.com/ganelson/inweb"><img src="../docs-assets/github.png" height=0> inweb</a></li>
<li><a href="https://github.com/ganelson/intest"><img src="../docs-assets/github.png" height=0> intest</a></li>
</ul>
		</nav>
		<main role="main">
		<!-- Weave of 'C Memory Model' generated by inweb -->
<div class="breadcrumbs">
    <ul class="crumbs"><li><a href="../index.html">Home</a></li><li><a href="../intern.html">Inter Modules</a></li><li><a href="index.html">final</a></li><li><a href="index.html#5">Chapter 5: C</a></li><li><b>C Memory Model</b></li></ul></div>
<p class="purpose">How arrays of all kinds are stored in C.</p>

<ul class="toc"><li><a href="5-cmm.html#SP1">&#167;1. Setting up the model</a></li></ul><hr class="tocbar">

<p class="commentary firstcommentary"><a id="SP1" class="paragraph-anchor"></a><b>&#167;1. Setting up the model.</b>The Inter semantics require that there be an area of byte-accessible memory:
</p>

<ul class="items"><li>(a) Byte-accessible memory must contain all of the arrays. These can but need
not have alignment gaps in between them. (For C, they do not.)
</li><li>(b) "Addresses" in this memory identify individual byte positions in it. These
can but need not start at 0. (For C, they do.) They must not be too large to
fit into an Inter value.
</li><li>(c) When an array name is compiled, its runtime value must be its address.
</li><li>(d) When an Inter value is stored in byte-accessible memory, it occupies either
2 or 4 consecutive bytes, with the little end first. The result is called a
"word". (For C, always 4, which is always <span class="extract"><span class="extract-syntax">sizeof(i7word_t)</span></span>.) Conversion between
a word stored in memory and an Inter value must be faithful in both directions.
</li><li>(e) Words can be stored at any byte position, and not only at (say) multiples
of 2 or 4.
</li><li>(f) Arrays in memory are free to contain a mixture of bytes and words: some do.
</li><li>(g) Data may be written in byte form and read back in word form, or vice versa.
</li></ul>
<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">CMemoryModel::initialise</span><button class="popup" onclick="togglePopup('usagePopup1')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup1">Usage of <span class="code-font"><span class="function-syntax">CMemoryModel::initialise</span></span>:<br/>Final C - <a href="5-fnc.html#SP1">&#167;1</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">code_generator</span><span class="plain-syntax"> *</span><span class="identifier-syntax">gtr</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">METHOD_ADD</span><span class="plain-syntax">(</span><span class="identifier-syntax">gtr</span><span class="plain-syntax">, </span><span class="constant-syntax">WORD_TO_BYTE_MTID</span><span class="plain-syntax">, </span><a href="5-cmm.html#SP11" class="function-link"><span class="function-syntax">CMemoryModel::word_to_byte</span></a><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">METHOD_ADD</span><span class="plain-syntax">(</span><span class="identifier-syntax">gtr</span><span class="plain-syntax">, </span><span class="constant-syntax">BEGIN_ARRAY_MTID</span><span class="plain-syntax">, </span><a href="5-cmm.html#SP4" class="function-link"><span class="function-syntax">CMemoryModel::begin_array</span></a><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">METHOD_ADD</span><span class="plain-syntax">(</span><span class="identifier-syntax">gtr</span><span class="plain-syntax">, </span><span class="constant-syntax">ARRAY_ENTRY_MTID</span><span class="plain-syntax">, </span><a href="5-cmm.html#SP5" class="function-link"><span class="function-syntax">CMemoryModel::array_entry</span></a><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">METHOD_ADD</span><span class="plain-syntax">(</span><span class="identifier-syntax">gtr</span><span class="plain-syntax">, </span><span class="constant-syntax">END_ARRAY_MTID</span><span class="plain-syntax">, </span><a href="5-cmm.html#SP6" class="function-link"><span class="function-syntax">CMemoryModel::end_array</span></a><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">typedef</span><span class="plain-syntax"> </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="reserved-syntax">C_generation_memory_model_data</span><span class="plain-syntax"> {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">himem</span><span class="plain-syntax">;                      </span><span class="comment-syntax"> 1 more than the largest legal byte address</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">struct</span><span class="plain-syntax"> </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">array_name</span><span class="plain-syntax">; </span><span class="comment-syntax"> of the array currently being compiled</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">entry_count</span><span class="plain-syntax">;                </span><span class="comment-syntax"> within the array currently being compiled</span>
<span class="plain-syntax">} </span><span class="reserved-syntax">C_generation_memory_model_data</span><span class="plain-syntax">;</span>

<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">CMemoryModel::initialise_data</span><button class="popup" onclick="togglePopup('usagePopup2')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup2">Usage of <span class="code-font"><span class="function-syntax">CMemoryModel::initialise_data</span></span>:<br/>Final C - <a href="5-fnc.html#SP4">&#167;4</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">code_generation</span><span class="plain-syntax"> *</span><span class="identifier-syntax">gen</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">C_GEN_DATA</span><span class="plain-syntax">(</span><span class="identifier-syntax">memdata</span><span class="plain-syntax">.</span><span class="element-syntax">himem</span><span class="plain-syntax">) = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">C_GEN_DATA</span><span class="plain-syntax">(</span><span class="identifier-syntax">memdata</span><span class="plain-syntax">.</span><span class="element-syntax">array_name</span><span class="plain-syntax">) = </span><span class="identifier-syntax">Str::new</span><span class="plain-syntax">();</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">C_GEN_DATA</span><span class="plain-syntax">(</span><span class="identifier-syntax">memdata</span><span class="plain-syntax">.</span><span class="element-syntax">entry_count</span><span class="plain-syntax">) = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<ul class="endnotetexts"><li>The structure C_generation_memory_model_data is accessed in 5/com and here.</li></ul>
<p class="commentary firstcommentary"><a id="SP2" class="paragraph-anchor"></a><b>&#167;2. </b>For a given process <span class="extract"><span class="extract-syntax">proc</span></span>, the current contents of byte-addressable memory will
be an array called <span class="extract"><span class="extract-syntax">proc-&gt;state.memory</span></span>; here, we will compile a single static array
<span class="extract"><span class="extract-syntax">i7_initial_memory</span></span> holding the initial contents of this memory, so that a new
process can be initialised from that.
</p>

<p class="commentary">The first 64 bytes of memory are reserved for the "header". We don't write those
here, and instead blank them out to all 0s.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">CMemoryModel::begin</span><button class="popup" onclick="togglePopup('usagePopup3')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup3">Usage of <span class="code-font"><span class="function-syntax">CMemoryModel::begin</span></span>:<br/>Final C - <a href="5-fnc.html#SP5">&#167;5</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">code_generation</span><span class="plain-syntax"> *</span><span class="identifier-syntax">gen</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">segmentation_pos</span><span class="plain-syntax"> </span><span class="identifier-syntax">saved</span><span class="plain-syntax"> = </span><a href="2-cg.html#SP12" class="function-link"><span class="function-syntax">CodeGen::select</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">, </span><span class="constant-syntax">c_memory_array_I7CGS</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">OUT</span><span class="plain-syntax"> = </span><a href="2-cg.html#SP14" class="function-link"><span class="function-syntax">CodeGen::current</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"i7byte_t i7_initial_memory[] = {\n"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">=0; </span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;64; </span><span class="identifier-syntax">i</span><span class="plain-syntax">++) </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"0, "</span><span class="plain-syntax">); </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"/* header */\n"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">C_GEN_DATA</span><span class="plain-syntax">(</span><span class="identifier-syntax">memdata</span><span class="plain-syntax">.</span><span class="element-syntax">himem</span><span class="plain-syntax">) += </span><span class="constant-syntax">64</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><a href="2-cg.html#SP12" class="function-link"><span class="function-syntax">CodeGen::deselect</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">, </span><span class="identifier-syntax">saved</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP3" class="paragraph-anchor"></a><b>&#167;3. </b>And we must close that array declaration, too:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">CMemoryModel::end</span><button class="popup" onclick="togglePopup('usagePopup4')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup4">Usage of <span class="code-font"><span class="function-syntax">CMemoryModel::end</span></span>:<br/>Final C - <a href="5-fnc.html#SP6">&#167;6</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">code_generation</span><span class="plain-syntax"> *</span><span class="identifier-syntax">gen</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">segmentation_pos</span><span class="plain-syntax"> </span><span class="identifier-syntax">saved</span><span class="plain-syntax"> = </span><a href="2-cg.html#SP12" class="function-link"><span class="function-syntax">CodeGen::select</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">, </span><span class="constant-syntax">c_memory_array_I7CGS</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">OUT</span><span class="plain-syntax"> = </span><a href="2-cg.html#SP14" class="function-link"><span class="function-syntax">CodeGen::current</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"};\n"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="2-cg.html#SP12" class="function-link"><span class="function-syntax">CodeGen::deselect</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">, </span><span class="identifier-syntax">saved</span><span class="plain-syntax">);</span>

<span class="plain-syntax">    </span><span class="identifier-syntax">saved</span><span class="plain-syntax"> = </span><a href="2-cg.html#SP12" class="function-link"><span class="function-syntax">CodeGen::select</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">, </span><span class="constant-syntax">c_ids_and_maxima_I7CGS</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">OUT</span><span class="plain-syntax"> = </span><a href="2-cg.html#SP14" class="function-link"><span class="function-syntax">CodeGen::current</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"#define i7_static_himem %d\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">C_GEN_DATA</span><span class="plain-syntax">(</span><span class="identifier-syntax">memdata</span><span class="plain-syntax">.</span><span class="element-syntax">himem</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    </span><a href="2-cg.html#SP12" class="function-link"><span class="function-syntax">CodeGen::deselect</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">, </span><span class="identifier-syntax">saved</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP4" class="paragraph-anchor"></a><b>&#167;4. </b>What goes into memory are arrays: memory is allocated only in the form of
such arrays, which are declared one at a time. See <a href="2-vc.html" class="internal">Vanilla Constants</a>.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">CMemoryModel::begin_array</span><button class="popup" onclick="togglePopup('usagePopup5')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup5">Usage of <span class="code-font"><span class="function-syntax">CMemoryModel::begin_array</span></span>:<br/><a href="5-cmm.html#SP1">&#167;1</a><br/>C Object Model - <a href="5-com.html#SP25_1">&#167;25.1</a>, <a href="5-com.html#SP25_2">&#167;25.2</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">code_generator</span><span class="plain-syntax"> *</span><span class="identifier-syntax">gtr</span><span class="plain-syntax">, </span><span class="reserved-syntax">code_generation</span><span class="plain-syntax"> *</span><span class="identifier-syntax">gen</span><span class="plain-syntax">,</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">array_name</span><span class="plain-syntax">, </span><span class="identifier-syntax">inter_symbol</span><span class="plain-syntax"> *</span><span class="identifier-syntax">array_s</span><span class="plain-syntax">, </span><span class="identifier-syntax">inter_tree_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">P</span><span class="plain-syntax">, </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">format</span><span class="plain-syntax">,</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">zero_count</span><span class="plain-syntax">, </span><span class="reserved-syntax">segmentation_pos</span><span class="plain-syntax"> *</span><span class="identifier-syntax">saved</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">Str::clear</span><span class="plain-syntax">(</span><span class="identifier-syntax">C_GEN_DATA</span><span class="plain-syntax">(</span><span class="identifier-syntax">memdata</span><span class="plain-syntax">.</span><span class="element-syntax">array_name</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">C_GEN_DATA</span><span class="plain-syntax">(</span><span class="identifier-syntax">memdata</span><span class="plain-syntax">.</span><span class="element-syntax">array_name</span><span class="plain-syntax">), </span><span class="string-syntax">"%S"</span><span class="plain-syntax">, </span><span class="identifier-syntax">array_name</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">C_GEN_DATA</span><span class="plain-syntax">(</span><span class="identifier-syntax">memdata</span><span class="plain-syntax">.</span><span class="element-syntax">entry_count</span><span class="plain-syntax">) = </span><span class="constant-syntax">0</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ConstantInstruction::list_format</span><span class="plain-syntax">(</span><span class="identifier-syntax">P</span><span class="plain-syntax">) == </span><span class="identifier-syntax">CONST_LIST_FORMAT_GRAMMAR</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="named-paragraph-container code-font"><a href="5-cmm.html#SP4_1" class="named-paragraph-link"><span class="named-paragraph">Short-circuit the usual Vanilla algorithm by compiling the whole array now</span><span class="named-paragraph-number">4.1</span></a></span>
<span class="plain-syntax">    </span><span class="reserved-syntax">else</span>
<span class="plain-syntax">        </span><span class="named-paragraph-container code-font"><a href="5-cmm.html#SP4_2" class="named-paragraph-link"><span class="named-paragraph">Declare this array in concert with the usual Vanilla algorithm</span><span class="named-paragraph-number">4.2</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP4_1" class="paragraph-anchor"></a><b>&#167;4.1. </b>Command-grammar arrays are handled differently: note the return value <span class="extract"><span class="extract-syntax">FALSE</span></span>,
which tells Vanilla not to call us again about this array.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Short-circuit the usual Vanilla algorithm by compiling the whole array now</span><span class="named-paragraph-number">4.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">saved</span><span class="plain-syntax">) *</span><span class="identifier-syntax">saved</span><span class="plain-syntax"> = </span><a href="2-cg.html#SP12" class="function-link"><span class="function-syntax">CodeGen::select</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">, </span><span class="constant-syntax">c_verb_arrays_I7CGS</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="2-vi.html#SP8" class="function-link"><span class="function-syntax">VanillaIF::verb_grammar</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gtr</span><span class="plain-syntax">, </span><span class="identifier-syntax">gen</span><span class="plain-syntax">, </span><span class="identifier-syntax">array_s</span><span class="plain-syntax">, </span><span class="identifier-syntax">P</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="5-cmm.html#SP4">&#167;4</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP4_2" class="paragraph-anchor"></a><b>&#167;4.2. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Declare this array in concert with the usual Vanilla algorithm</span><span class="named-paragraph-number">4.2</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">saved</span><span class="plain-syntax">) *</span><span class="identifier-syntax">saved</span><span class="plain-syntax"> = </span><a href="2-cg.html#SP12" class="function-link"><span class="function-syntax">CodeGen::select</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">, </span><span class="constant-syntax">c_arrays_I7CGS</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">format_name</span><span class="plain-syntax"> = </span><span class="identifier-syntax">I</span><span class="string-syntax">"unknown"</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="5-cmm.html#SP4_2_1" class="named-paragraph-link"><span class="named-paragraph">Work out the format name</span><span class="named-paragraph-number">4.2.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="named-paragraph-container code-font"><a href="5-cmm.html#SP4_2_2" class="named-paragraph-link"><span class="named-paragraph">Define a constant for the byte address in memory where the array begins</span><span class="named-paragraph-number">4.2.2</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">format</span><span class="plain-syntax"> == </span><span class="constant-syntax">TABLE_ARRAY_FORMAT</span><span class="plain-syntax">) || (</span><span class="identifier-syntax">format</span><span class="plain-syntax"> == </span><span class="constant-syntax">BUFFER_ARRAY_FORMAT</span><span class="plain-syntax">))</span>
<span class="plain-syntax">        </span><span class="named-paragraph-container code-font"><a href="5-cmm.html#SP4_2_3" class="named-paragraph-link"><span class="named-paragraph">Place the extent entry N at index 0</span><span class="named-paragraph-number">4.2.3</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">for</span><span class="plain-syntax"> (</span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">i</span><span class="plain-syntax">=0; </span><span class="identifier-syntax">i</span><span class="plain-syntax">&lt;</span><span class="identifier-syntax">zero_count</span><span class="plain-syntax">; </span><span class="identifier-syntax">i</span><span class="plain-syntax">++) </span><a href="5-cmm.html#SP5" class="function-link"><span class="function-syntax">CMemoryModel::array_entry</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gtr</span><span class="plain-syntax">, </span><span class="identifier-syntax">gen</span><span class="plain-syntax">, </span><span class="identifier-syntax">I</span><span class="string-syntax">"0"</span><span class="plain-syntax">, </span><span class="identifier-syntax">format</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="5-cmm.html#SP4">&#167;4</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP4_2_1" class="paragraph-anchor"></a><b>&#167;4.2.1. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Work out the format name</span><span class="named-paragraph-number">4.2.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">switch</span><span class="plain-syntax"> (</span><span class="identifier-syntax">format</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">BYTE_ARRAY_FORMAT:</span><span class="plain-syntax"> </span><span class="identifier-syntax">format_name</span><span class="plain-syntax"> = </span><span class="identifier-syntax">I</span><span class="string-syntax">"byte"</span><span class="plain-syntax">; </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">WORD_ARRAY_FORMAT:</span><span class="plain-syntax"> </span><span class="identifier-syntax">format_name</span><span class="plain-syntax"> = </span><span class="identifier-syntax">I</span><span class="string-syntax">"word"</span><span class="plain-syntax">; </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">BUFFER_ARRAY_FORMAT:</span><span class="plain-syntax"> </span><span class="identifier-syntax">format_name</span><span class="plain-syntax"> = </span><span class="identifier-syntax">I</span><span class="string-syntax">"buffer"</span><span class="plain-syntax">; </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">TABLE_ARRAY_FORMAT:</span><span class="plain-syntax"> </span><span class="identifier-syntax">format_name</span><span class="plain-syntax"> = </span><span class="identifier-syntax">I</span><span class="string-syntax">"table"</span><span class="plain-syntax">; </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="5-cmm.html#SP4_2">&#167;4.2</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP4_2_2" class="paragraph-anchor"></a><b>&#167;4.2.2. </b>Crucially, the array names are <span class="extract"><span class="extract-syntax">#define</span></span> constants declared up near the top
of the source code: they are not variables with pointer types, or something
like that. This means they can legally be used as values elsewhere in memory,
or as initial values of variables, and so on.
</p>

<p class="commentary">Object, class and function names can also legally appear as array entries,
because they too are defined constants, equal to their IDs: see <a href="5-com.html" class="internal">C Object Model</a>.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Define a constant for the byte address in memory where the array begins</span><span class="named-paragraph-number">4.2.2</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="reserved-syntax">segmentation_pos</span><span class="plain-syntax"> </span><span class="identifier-syntax">saved</span><span class="plain-syntax"> = </span><a href="2-cg.html#SP12" class="function-link"><span class="function-syntax">CodeGen::select</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">, </span><span class="constant-syntax">c_predeclarations_I7CGS</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">OUT</span><span class="plain-syntax"> = </span><a href="2-cg.html#SP14" class="function-link"><span class="function-syntax">CodeGen::current</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"#define "</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="5-cnm.html#SP3" class="function-link"><span class="function-syntax">CNamespace::mangle</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gtr</span><span class="plain-syntax">, </span><span class="identifier-syntax">OUT</span><span class="plain-syntax">, </span><span class="identifier-syntax">array_name</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">" %d /* = position in memory of %S array %S */\n"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">C_GEN_DATA</span><span class="plain-syntax">(</span><span class="identifier-syntax">memdata</span><span class="plain-syntax">.</span><span class="element-syntax">himem</span><span class="plain-syntax">), </span><span class="identifier-syntax">format_name</span><span class="plain-syntax">, </span><span class="identifier-syntax">array_name</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">array_s</span><span class="plain-syntax">)</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">SymbolAnnotation::set_i</span><span class="plain-syntax">(</span><span class="identifier-syntax">array_s</span><span class="plain-syntax">, </span><span class="identifier-syntax">C_ARRAY_ADDRESS_IANN</span><span class="plain-syntax">,</span>
<span class="plain-syntax">            (</span><span class="identifier-syntax">inter_ti</span><span class="plain-syntax">) </span><span class="identifier-syntax">C_GEN_DATA</span><span class="plain-syntax">(</span><span class="identifier-syntax">memdata</span><span class="plain-syntax">.</span><span class="element-syntax">himem</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    </span><a href="2-cg.html#SP12" class="function-link"><span class="function-syntax">CodeGen::deselect</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">, </span><span class="identifier-syntax">saved</span><span class="plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="5-cmm.html#SP4_2">&#167;4.2</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP4_2_3" class="paragraph-anchor"></a><b>&#167;4.2.3. </b>Of course, right now we don't know <span class="extract"><span class="extract-syntax">N</span></span>, the extent of the array. So we will
refer to this with a constant like <span class="extract"><span class="extract-syntax">i7_mgl_myarray__xt</span></span> (XT meaning "extent"),
which we will retrospectively predefine when the array ends.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">Place the extent entry N at index 0</span><span class="named-paragraph-number">4.2.3</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">TEMPORARY_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">extname</span><span class="plain-syntax">)</span>
<span class="plain-syntax">    </span><a href="5-cnm.html#SP3" class="function-link"><span class="function-syntax">CNamespace::mangle</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gtr</span><span class="plain-syntax">, </span><span class="identifier-syntax">extname</span><span class="plain-syntax">, </span><span class="identifier-syntax">array_name</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">WRITE_TO</span><span class="plain-syntax">(</span><span class="identifier-syntax">extname</span><span class="plain-syntax">, </span><span class="string-syntax">"__xt"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="5-cmm.html#SP5" class="function-link"><span class="function-syntax">CMemoryModel::array_entry</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gtr</span><span class="plain-syntax">, </span><span class="identifier-syntax">gen</span><span class="plain-syntax">, </span><span class="identifier-syntax">extname</span><span class="plain-syntax">, </span><span class="identifier-syntax">format</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">DISCARD_TEXT</span><span class="plain-syntax">(</span><span class="identifier-syntax">extname</span><span class="plain-syntax">)</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="5-cmm.html#SP4_2">&#167;4.2</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP5" class="paragraph-anchor"></a><b>&#167;5. </b>The call to <a href="5-cmm.html#SP4" class="internal">CMemoryModel::begin_array</a> is then followed by a series of calls to:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">CMemoryModel::array_entry</span><button class="popup" onclick="togglePopup('usagePopup6')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup6">Usage of <span class="code-font"><span class="function-syntax">CMemoryModel::array_entry</span></span>:<br/><a href="5-cmm.html#SP1">&#167;1</a>, <a href="5-cmm.html#SP4_2">&#167;4.2</a>, <a href="5-cmm.html#SP4_2_3">&#167;4.2.3</a><br/>C Object Model - <a href="5-com.html#SP24">&#167;24</a>, <a href="5-com.html#SP25_1">&#167;25.1</a>, <a href="5-com.html#SP25_2">&#167;25.2</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">code_generator</span><span class="plain-syntax"> *</span><span class="identifier-syntax">gtr</span><span class="plain-syntax">, </span><span class="reserved-syntax">code_generation</span><span class="plain-syntax"> *</span><span class="identifier-syntax">gen</span><span class="plain-syntax">,</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">entry</span><span class="plain-syntax">, </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">format</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">segmentation_pos</span><span class="plain-syntax"> </span><span class="identifier-syntax">saved</span><span class="plain-syntax"> = </span><a href="2-cg.html#SP12" class="function-link"><span class="function-syntax">CodeGen::select</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">, </span><span class="constant-syntax">c_memory_array_I7CGS</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">OUT</span><span class="plain-syntax"> = </span><a href="2-cg.html#SP14" class="function-link"><span class="function-syntax">CodeGen::current</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> ((</span><span class="identifier-syntax">format</span><span class="plain-syntax"> == </span><span class="constant-syntax">TABLE_ARRAY_FORMAT</span><span class="plain-syntax">) || (</span><span class="identifier-syntax">format</span><span class="plain-syntax"> == </span><span class="constant-syntax">WORD_ARRAY_FORMAT</span><span class="plain-syntax">))</span>
<span class="plain-syntax">        </span><span class="named-paragraph-container code-font"><a href="5-cmm.html#SP5_2" class="named-paragraph-link"><span class="named-paragraph">This is a word entry</span><span class="named-paragraph-number">5.2</span></a></span>
<span class="plain-syntax">    </span><span class="reserved-syntax">else</span>
<span class="plain-syntax">        </span><span class="named-paragraph-container code-font"><a href="5-cmm.html#SP5_1" class="named-paragraph-link"><span class="named-paragraph">This is a byte entry</span><span class="named-paragraph-number">5.1</span></a></span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><a href="2-cg.html#SP12" class="function-link"><span class="function-syntax">CodeGen::deselect</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">, </span><span class="identifier-syntax">saved</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">C_GEN_DATA</span><span class="plain-syntax">(</span><span class="identifier-syntax">memdata</span><span class="plain-syntax">.</span><span class="element-syntax">entry_count</span><span class="plain-syntax">)++;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP5_1" class="paragraph-anchor"></a><b>&#167;5.1. </b><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">This is a byte entry</span><span class="named-paragraph-number">5.1</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"    (i7byte_t) %S, /* %d */\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">entry</span><span class="plain-syntax">, </span><span class="identifier-syntax">C_GEN_DATA</span><span class="plain-syntax">(</span><span class="identifier-syntax">memdata</span><span class="plain-syntax">.</span><span class="element-syntax">himem</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">C_GEN_DATA</span><span class="plain-syntax">(</span><span class="identifier-syntax">memdata</span><span class="plain-syntax">.</span><span class="element-syntax">himem</span><span class="plain-syntax">) += </span><span class="constant-syntax">1</span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="5-cmm.html#SP5">&#167;5</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP5_2" class="paragraph-anchor"></a><b>&#167;5.2. </b>Note that <span class="extract"><span class="extract-syntax">I7BYTE_0</span></span> and so on are macros and not functions (see below): they
use only arithmetic operations which can be constant-folded by the C compiler,
and therefore if <span class="extract"><span class="extract-syntax">X</span></span> is a valid constant-context expression in C then so is
<span class="extract"><span class="extract-syntax">I7BYTE_0(X)</span></span>.
</p>

<p class="commentary"><span class="named-paragraph-container code-font"><span class="named-paragraph-defn">This is a word entry</span><span class="named-paragraph-number">5.2</span></span><span class="comment-syntax"> =</span>
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="plain-syntax">    </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"    I7BYTE_0(%S), I7BYTE_1(%S), I7BYTE_2(%S), I7BYTE_3(%S), /* %d */\n"</span><span class="plain-syntax">,</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">entry</span><span class="plain-syntax">, </span><span class="identifier-syntax">entry</span><span class="plain-syntax">, </span><span class="identifier-syntax">entry</span><span class="plain-syntax">, </span><span class="identifier-syntax">entry</span><span class="plain-syntax">, </span><span class="identifier-syntax">C_GEN_DATA</span><span class="plain-syntax">(</span><span class="identifier-syntax">memdata</span><span class="plain-syntax">.</span><span class="element-syntax">himem</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">C_GEN_DATA</span><span class="plain-syntax">(</span><span class="identifier-syntax">memdata</span><span class="plain-syntax">.</span><span class="element-syntax">himem</span><span class="plain-syntax">) += </span><span class="constant-syntax">4</span><span class="plain-syntax">;</span>
</pre>
<ul class="endnotetexts"><li>This code is used in <a href="5-cmm.html#SP5">&#167;5</a>.</li></ul>
<p class="commentary firstcommentary"><a id="SP6" class="paragraph-anchor"></a><b>&#167;6. </b>When all the entries have been placed, the following is called. It does nothing
except to predeclare the extent constant.
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">CMemoryModel::end_array</span><button class="popup" onclick="togglePopup('usagePopup7')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup7">Usage of <span class="code-font"><span class="function-syntax">CMemoryModel::end_array</span></span>:<br/><a href="5-cmm.html#SP1">&#167;1</a><br/>C Object Model - <a href="5-com.html#SP25_1">&#167;25.1</a>, <a href="5-com.html#SP25_2">&#167;25.2</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">code_generator</span><span class="plain-syntax"> *</span><span class="identifier-syntax">gtr</span><span class="plain-syntax">, </span><span class="reserved-syntax">code_generation</span><span class="plain-syntax"> *</span><span class="identifier-syntax">gen</span><span class="plain-syntax">, </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">format</span><span class="plain-syntax">,</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">zero_count</span><span class="plain-syntax">, </span><span class="reserved-syntax">segmentation_pos</span><span class="plain-syntax"> *</span><span class="identifier-syntax">saved</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">segmentation_pos</span><span class="plain-syntax"> </span><span class="identifier-syntax">x_saved</span><span class="plain-syntax"> = </span><a href="2-cg.html#SP12" class="function-link"><span class="function-syntax">CodeGen::select</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">, </span><span class="constant-syntax">c_predeclarations_I7CGS</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">OUT</span><span class="plain-syntax"> = </span><a href="2-cg.html#SP14" class="function-link"><span class="function-syntax">CodeGen::current</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"#define "</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><a href="5-cnm.html#SP3" class="function-link"><span class="function-syntax">CNamespace::mangle</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gtr</span><span class="plain-syntax">, </span><span class="identifier-syntax">OUT</span><span class="plain-syntax">, </span><span class="identifier-syntax">C_GEN_DATA</span><span class="plain-syntax">(</span><span class="identifier-syntax">memdata</span><span class="plain-syntax">.</span><span class="element-syntax">array_name</span><span class="plain-syntax">));</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"__xt %d\n"</span><span class="plain-syntax">, </span><span class="identifier-syntax">C_GEN_DATA</span><span class="plain-syntax">(</span><span class="identifier-syntax">memdata</span><span class="plain-syntax">.</span><span class="element-syntax">entry_count</span><span class="plain-syntax">)-1);</span>
<span class="plain-syntax">    </span><a href="2-cg.html#SP12" class="function-link"><span class="function-syntax">CodeGen::deselect</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">, </span><span class="identifier-syntax">x_saved</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">saved</span><span class="plain-syntax">) </span><a href="2-cg.html#SP12" class="function-link"><span class="function-syntax">CodeGen::deselect</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">, *</span><span class="identifier-syntax">saved</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP7" class="paragraph-anchor"></a><b>&#167;7. </b>The primitives for byte and word lookup have the signatures:
</p>

<pre class="displayed-code all-displayed-code code-font">
<span class="identifier-syntax">primitive</span><span class="plain-syntax"> !</span><span class="identifier-syntax">lookup</span><span class="plain-syntax"> </span><span class="identifier-syntax">val</span><span class="plain-syntax"> </span><span class="identifier-syntax">val</span><span class="plain-syntax"> -&gt; </span><span class="identifier-syntax">val</span>
<span class="identifier-syntax">primitive</span><span class="plain-syntax"> !</span><span class="identifier-syntax">lookupbyte</span><span class="plain-syntax"> </span><span class="identifier-syntax">val</span><span class="plain-syntax"> </span><span class="identifier-syntax">val</span><span class="plain-syntax"> -&gt; </span><span class="identifier-syntax">val</span>
</pre>
<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">CMemoryModel::handle_store_by_ref</span><span class="plain-syntax">(</span><span class="reserved-syntax">code_generation</span><span class="plain-syntax"> *</span><span class="identifier-syntax">gen</span><span class="plain-syntax">, </span><span class="identifier-syntax">inter_tree_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">ref</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ReferenceInstruction::node_is_ref_to</span><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">from</span><span class="plain-syntax">, </span><span class="identifier-syntax">ref</span><span class="plain-syntax">, </span><span class="identifier-syntax">LOOKUP_BIP</span><span class="plain-syntax">)) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">if</span><span class="plain-syntax"> (</span><span class="identifier-syntax">ReferenceInstruction::node_is_ref_to</span><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">-&gt;</span><span class="element-syntax">from</span><span class="plain-syntax">, </span><span class="identifier-syntax">ref</span><span class="plain-syntax">, </span><span class="identifier-syntax">LOOKUPBYTE_BIP</span><span class="plain-syntax">)) </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">TRUE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>

<span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="function-syntax">CMemoryModel::invoke_primitive</span><button class="popup" onclick="togglePopup('usagePopup8')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup8">Usage of <span class="code-font"><span class="function-syntax">CMemoryModel::invoke_primitive</span></span>:<br/>C Program Control - <a href="5-cpc.html#SP1">&#167;1</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">code_generation</span><span class="plain-syntax"> *</span><span class="identifier-syntax">gen</span><span class="plain-syntax">, </span><span class="identifier-syntax">inter_ti</span><span class="plain-syntax"> </span><span class="identifier-syntax">bip</span><span class="plain-syntax">, </span><span class="identifier-syntax">inter_tree_node</span><span class="plain-syntax"> *</span><span class="identifier-syntax">P</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">OUT</span><span class="plain-syntax"> = </span><a href="2-cg.html#SP14" class="function-link"><span class="function-syntax">CodeGen::current</span></a><span class="plain-syntax">(</span><span class="identifier-syntax">gen</span><span class="plain-syntax">);</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">switch</span><span class="plain-syntax"> (</span><span class="identifier-syntax">bip</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">LOOKUP_BIP:</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"i7_read_word(proc, "</span><span class="plain-syntax">); </span><span class="constant-syntax">VNODE_1C</span><span class="plain-syntax">; </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">", "</span><span class="plain-syntax">); </span><span class="constant-syntax">VNODE_2C</span><span class="plain-syntax">; </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">")"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="reserved-syntax">case</span><span class="plain-syntax"> </span><span class="identifier-syntax">LOOKUPBYTE_BIP:</span>
<span class="plain-syntax">            </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"i7_read_byte(proc, "</span><span class="plain-syntax">); </span><span class="constant-syntax">VNODE_1C</span><span class="plain-syntax">; </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">" + "</span><span class="plain-syntax">); </span><span class="constant-syntax">VNODE_2C</span><span class="plain-syntax">; </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">")"</span><span class="plain-syntax">);</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">break</span><span class="plain-syntax">;</span>
<span class="plain-syntax">        </span><span class="identifier-syntax">default:</span>
<span class="plain-syntax">            </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">NOT_APPLICABLE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">    }</span>
<span class="plain-syntax">    </span><span class="reserved-syntax">return</span><span class="plain-syntax"> </span><span class="identifier-syntax">FALSE</span><span class="plain-syntax">;</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP8" class="paragraph-anchor"></a><b>&#167;8. </b>So, then, time to write some more of the C library. We are going to need to
define the macros <span class="extract"><span class="extract-syntax">I7BYTE_0</span></span> to <span class="extract"><span class="extract-syntax">I7BYTE_3</span></span>, and also the functions <span class="extract"><span class="extract-syntax">i7_read_word</span></span>
and <span class="extract"><span class="extract-syntax">i7_read_byte</span></span>, used just above. But we start with the function which resets
memory to its initial state when a process begins, and with the stack empty.
</p>

<p class="commentary">Note that we fill in ten bytes of the 64-byte header block of memory:
</p>

<ul class="items"><li>&#9679; The Release number as a big-endian 16-bit value at <span class="extract"><span class="extract-syntax">0x34-0x35</span></span>;
</li><li>&#9679; The Serial code as six ASCII characters (in practice digits) at <span class="extract"><span class="extract-syntax">0x36-0x3B</span></span>.
</li></ul>
<p class="commentary">We carefully defined those two constants, if they exist, before the inclusion point of
the C library in order that the conditional compilations in <span class="extract"><span class="extract-syntax">i7_initialise_memory_and_stack</span></span>
will work correctly. See <a href="5-cnm.html#SP7" class="internal">CNamespace::declare_constant</a>.
</p>

<p class="commentary">The rest of the header area remains all zeros.
</p>

<pre class="Extracts-displayed-code all-displayed-code code-font">
<span class="Extracts-identifier-syntax">void</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">i7_calloc</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">i7process_t</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">size_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">how_many</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">size_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">of_size</span><span class="Extracts-plain-syntax">);</span>
<span class="Extracts-identifier-syntax">void</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_initialise_memory_and_stack</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">i7process_t</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This is part of the extract file inform7_clib.h.</li></ul>
<pre class="Extracts-displayed-code all-displayed-code code-font">
<span class="Extracts-identifier-syntax">void</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">i7_calloc</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">i7process_t</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">size_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">how_many</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">size_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">of_size</span><span class="Extracts-plain-syntax">) {</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">void</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">p</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">calloc</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">how_many</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">of_size</span><span class="Extracts-plain-syntax">);</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">if</span><span class="Extracts-plain-syntax"> (</span><span class="Extracts-identifier-syntax">p</span><span class="Extracts-plain-syntax"> == </span><span class="Extracts-identifier-syntax">NULL</span><span class="Extracts-plain-syntax">) {</span>
<span class="Extracts-plain-syntax">        </span><span class="Extracts-identifier-syntax">printf</span><span class="Extracts-plain-syntax">("</span><span class="Extracts-identifier-syntax">Memory</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">allocation</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">failed</span><span class="Extracts-plain-syntax">\</span><span class="Extracts-identifier-syntax">n</span><span class="Extracts-plain-syntax">");</span>
<span class="Extracts-plain-syntax">        </span><span class="Extracts-identifier-syntax">i7_fatal_exit</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">);</span>
<span class="Extracts-plain-syntax">    }</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">return</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">p</span><span class="Extracts-plain-syntax">;</span>
<span class="Extracts-plain-syntax">}</span>

<span class="Extracts-identifier-syntax">i7byte_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_initial_memory</span><span class="Extracts-plain-syntax">[];</span>
<span class="Extracts-identifier-syntax">void</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_initialise_memory_and_stack</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">i7process_t</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">) {</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">if</span><span class="Extracts-plain-syntax"> (</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">state</span><span class="Extracts-plain-syntax">.</span><span class="Extracts-identifier-syntax">memory</span><span class="Extracts-plain-syntax"> != </span><span class="Extracts-identifier-syntax">NULL</span><span class="Extracts-plain-syntax">) </span><span class="Extracts-identifier-syntax">free</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">state</span><span class="Extracts-plain-syntax">.</span><span class="Extracts-identifier-syntax">memory</span><span class="Extracts-plain-syntax">);</span>

<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">i7byte_t</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">mem</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">i7_calloc</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">i7_static_himem</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">sizeof</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">i7byte_t</span><span class="Extracts-plain-syntax">));</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">for</span><span class="Extracts-plain-syntax"> (</span><span class="Extracts-identifier-syntax">int</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i</span><span class="Extracts-plain-syntax">=0; </span><span class="Extracts-identifier-syntax">i</span><span class="Extracts-plain-syntax">&lt;</span><span class="Extracts-identifier-syntax">i7_static_himem</span><span class="Extracts-plain-syntax">; </span><span class="Extracts-identifier-syntax">i</span><span class="Extracts-plain-syntax">++) </span><span class="Extracts-identifier-syntax">mem</span><span class="Extracts-plain-syntax">[</span><span class="Extracts-identifier-syntax">i</span><span class="Extracts-plain-syntax">] = </span><span class="Extracts-identifier-syntax">i7_initial_memory</span><span class="Extracts-plain-syntax">[</span><span class="Extracts-identifier-syntax">i</span><span class="Extracts-plain-syntax">];</span>
<span class="Extracts-plain-syntax">    #</span><span class="Extracts-identifier-syntax">ifdef</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_mgl_Release</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">mem</span><span class="Extracts-plain-syntax">[0</span><span class="Extracts-identifier-syntax">x34</span><span class="Extracts-plain-syntax">] = </span><span class="Extracts-identifier-syntax">I7BYTE_2</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">i7_mgl_Release</span><span class="Extracts-plain-syntax">); </span><span class="Extracts-identifier-syntax">mem</span><span class="Extracts-plain-syntax">[0</span><span class="Extracts-identifier-syntax">x35</span><span class="Extracts-plain-syntax">] = </span><span class="Extracts-identifier-syntax">I7BYTE_3</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">i7_mgl_Release</span><span class="Extracts-plain-syntax">);</span>
<span class="Extracts-plain-syntax">    #</span><span class="Extracts-identifier-syntax">endif</span>
<span class="Extracts-plain-syntax">    #</span><span class="Extracts-identifier-syntax">ifndef</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_mgl_Release</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">mem</span><span class="Extracts-plain-syntax">[0</span><span class="Extracts-identifier-syntax">x34</span><span class="Extracts-plain-syntax">] = </span><span class="Extracts-identifier-syntax">I7BYTE_2</span><span class="Extracts-plain-syntax">(1); </span><span class="Extracts-identifier-syntax">mem</span><span class="Extracts-plain-syntax">[0</span><span class="Extracts-identifier-syntax">x35</span><span class="Extracts-plain-syntax">] = </span><span class="Extracts-identifier-syntax">I7BYTE_3</span><span class="Extracts-plain-syntax">(1);</span>
<span class="Extracts-plain-syntax">    #</span><span class="Extracts-identifier-syntax">endif</span>
<span class="Extracts-plain-syntax">    #</span><span class="Extracts-identifier-syntax">ifdef</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_mgl_Serial</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">char</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">p</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">i7_text_to_C_string</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">i7_mgl_Serial</span><span class="Extracts-plain-syntax">);</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">for</span><span class="Extracts-plain-syntax"> (</span><span class="Extracts-identifier-syntax">int</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i</span><span class="Extracts-plain-syntax">=0; </span><span class="Extracts-identifier-syntax">i</span><span class="Extracts-plain-syntax">&lt;6; </span><span class="Extracts-identifier-syntax">i</span><span class="Extracts-plain-syntax">++) </span><span class="Extracts-identifier-syntax">mem</span><span class="Extracts-plain-syntax">[0</span><span class="Extracts-identifier-syntax">x36</span><span class="Extracts-plain-syntax"> + </span><span class="Extracts-identifier-syntax">i</span><span class="Extracts-plain-syntax">] = </span><span class="Extracts-identifier-syntax">p</span><span class="Extracts-plain-syntax">[</span><span class="Extracts-identifier-syntax">i</span><span class="Extracts-plain-syntax">];</span>
<span class="Extracts-plain-syntax">    #</span><span class="Extracts-identifier-syntax">endif</span>
<span class="Extracts-plain-syntax">    #</span><span class="Extracts-identifier-syntax">ifndef</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_mgl_Serial</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">for</span><span class="Extracts-plain-syntax"> (</span><span class="Extracts-identifier-syntax">int</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i</span><span class="Extracts-plain-syntax">=0; </span><span class="Extracts-identifier-syntax">i</span><span class="Extracts-plain-syntax">&lt;6; </span><span class="Extracts-identifier-syntax">i</span><span class="Extracts-plain-syntax">++) </span><span class="Extracts-identifier-syntax">mem</span><span class="Extracts-plain-syntax">[0</span><span class="Extracts-identifier-syntax">x36</span><span class="Extracts-plain-syntax"> + </span><span class="Extracts-identifier-syntax">i</span><span class="Extracts-plain-syntax">] = '0';</span>
<span class="Extracts-plain-syntax">    #</span><span class="Extracts-identifier-syntax">endif</span>

<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">state</span><span class="Extracts-plain-syntax">.</span><span class="Extracts-identifier-syntax">memory</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">mem</span><span class="Extracts-plain-syntax">;</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">state</span><span class="Extracts-plain-syntax">.</span><span class="Extracts-identifier-syntax">himem</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">i7_static_himem</span><span class="Extracts-plain-syntax">;</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">state</span><span class="Extracts-plain-syntax">.</span><span class="Extracts-identifier-syntax">stack_pointer</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-constant-syntax">0</span><span class="Extracts-plain-syntax">;</span>
<span class="Extracts-plain-syntax">}</span>
</pre>
<ul class="endnotetexts"><li>This is part of the extract file inform7_clib.c.</li></ul>
<p class="commentary firstcommentary"><a id="SP9" class="paragraph-anchor"></a><b>&#167;9. </b>The array <span class="extract"><span class="Extracts-extract-syntax">proc-&gt;state.memory</span></span> is of <span class="extract"><span class="Extracts-extract-syntax">i7byte_t</span></span> values, so it's easy to read
and write bytes. Words are more challenging since we need to pack and unpack them.
</p>

<p class="commentary">The <span class="extract"><span class="Extracts-extract-syntax">i7_read_word</span></span> function reads a word which is in word entry <span class="extract"><span class="Extracts-extract-syntax">array_index</span></span> (counting
0, 1, 2, ...) in the array which begins at the byte address <span class="extract"><span class="Extracts-extract-syntax">array_address</span></span>.
</p>

<p class="commentary">We can also read "short words", that is, 16-bit values.
</p>

<pre class="Extracts-displayed-code all-displayed-code code-font">
<span class="Extracts-identifier-syntax">i7byte_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_read_byte</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">i7process_t</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">i7word_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">address</span><span class="Extracts-plain-syntax">);</span>
<span class="Extracts-identifier-syntax">i7word_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_read_sword</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">i7process_t</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">i7word_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">array_address</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">i7word_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">array_index</span><span class="Extracts-plain-syntax">);</span>
<span class="Extracts-identifier-syntax">i7word_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_read_word</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">i7process_t</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">i7word_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">array_address</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">i7word_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">array_index</span><span class="Extracts-plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This is part of the extract file inform7_clib.h.</li></ul>
<pre class="Extracts-displayed-code all-displayed-code code-font">
<span class="Extracts-identifier-syntax">i7byte_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_read_byte</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">i7process_t</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">i7word_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">address</span><span class="Extracts-plain-syntax">) {</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">return</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">state</span><span class="Extracts-plain-syntax">.</span><span class="Extracts-identifier-syntax">memory</span><span class="Extracts-plain-syntax">[</span><span class="Extracts-identifier-syntax">address</span><span class="Extracts-plain-syntax">];</span>
<span class="Extracts-plain-syntax">}</span>

<span class="Extracts-identifier-syntax">i7word_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_read_sword</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">i7process_t</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">i7word_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">array_address</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">i7word_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">array_index</span><span class="Extracts-plain-syntax">) {</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">i7byte_t</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">data</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">state</span><span class="Extracts-plain-syntax">.</span><span class="Extracts-identifier-syntax">memory</span><span class="Extracts-plain-syntax">;</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">int</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">byte_position</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">array_address</span><span class="Extracts-plain-syntax"> + </span><span class="Extracts-constant-syntax">2</span><span class="Extracts-plain-syntax">*</span><span class="Extracts-identifier-syntax">array_index</span><span class="Extracts-plain-syntax">;</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">if</span><span class="Extracts-plain-syntax"> ((</span><span class="Extracts-identifier-syntax">byte_position</span><span class="Extracts-plain-syntax"> &lt; </span><span class="Extracts-constant-syntax">0</span><span class="Extracts-plain-syntax">) || (</span><span class="Extracts-identifier-syntax">byte_position</span><span class="Extracts-plain-syntax"> &gt;= </span><span class="Extracts-identifier-syntax">i7_static_himem</span><span class="Extracts-plain-syntax">)) {</span>
<span class="Extracts-plain-syntax">        </span><span class="Extracts-identifier-syntax">printf</span><span class="Extracts-plain-syntax">("</span><span class="Extracts-identifier-syntax">Memory</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">access</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">out</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">of</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">range</span><span class="Extracts-plain-syntax">: %</span><span class="Extracts-identifier-syntax">d</span><span class="Extracts-plain-syntax">\</span><span class="Extracts-identifier-syntax">n</span><span class="Extracts-plain-syntax">", </span><span class="Extracts-identifier-syntax">byte_position</span><span class="Extracts-plain-syntax">);</span>
<span class="Extracts-plain-syntax">        </span><span class="Extracts-identifier-syntax">i7_fatal_exit</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">);</span>
<span class="Extracts-plain-syntax">    }</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">return</span><span class="Extracts-plain-syntax">             (</span><span class="Extracts-identifier-syntax">i7word_t</span><span class="Extracts-plain-syntax">) </span><span class="Extracts-identifier-syntax">data</span><span class="Extracts-plain-syntax">[</span><span class="Extracts-identifier-syntax">byte_position</span><span class="Extracts-plain-syntax"> + </span><span class="Extracts-constant-syntax">1</span><span class="Extracts-plain-syntax">]  +</span>
<span class="Extracts-plain-syntax">                </span><span class="Extracts-constant-syntax">0</span><span class="Extracts-identifier-syntax">x100U</span><span class="Extracts-plain-syntax">*((</span><span class="Extracts-identifier-syntax">i7word_t</span><span class="Extracts-plain-syntax">) </span><span class="Extracts-identifier-syntax">data</span><span class="Extracts-plain-syntax">[</span><span class="Extracts-identifier-syntax">byte_position</span><span class="Extracts-plain-syntax"> + </span><span class="Extracts-constant-syntax">0</span><span class="Extracts-plain-syntax">]);</span>
<span class="Extracts-plain-syntax">}</span>

<span class="Extracts-identifier-syntax">i7word_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_read_word</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">i7process_t</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">i7word_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">array_address</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">i7word_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">array_index</span><span class="Extracts-plain-syntax">) {</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">i7byte_t</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">data</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">state</span><span class="Extracts-plain-syntax">.</span><span class="Extracts-identifier-syntax">memory</span><span class="Extracts-plain-syntax">;</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">int</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">byte_position</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">array_address</span><span class="Extracts-plain-syntax"> + </span><span class="Extracts-constant-syntax">4</span><span class="Extracts-plain-syntax">*</span><span class="Extracts-identifier-syntax">array_index</span><span class="Extracts-plain-syntax">;</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">if</span><span class="Extracts-plain-syntax"> ((</span><span class="Extracts-identifier-syntax">byte_position</span><span class="Extracts-plain-syntax"> &lt; </span><span class="Extracts-constant-syntax">0</span><span class="Extracts-plain-syntax">) || (</span><span class="Extracts-identifier-syntax">byte_position</span><span class="Extracts-plain-syntax"> &gt;= </span><span class="Extracts-identifier-syntax">i7_static_himem</span><span class="Extracts-plain-syntax">)) {</span>
<span class="Extracts-plain-syntax">        </span><span class="Extracts-identifier-syntax">printf</span><span class="Extracts-plain-syntax">("</span><span class="Extracts-identifier-syntax">Memory</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">access</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">out</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">of</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">range</span><span class="Extracts-plain-syntax">: %</span><span class="Extracts-identifier-syntax">d</span><span class="Extracts-plain-syntax">\</span><span class="Extracts-identifier-syntax">n</span><span class="Extracts-plain-syntax">", </span><span class="Extracts-identifier-syntax">byte_position</span><span class="Extracts-plain-syntax">);</span>
<span class="Extracts-plain-syntax">        </span><span class="Extracts-identifier-syntax">i7_fatal_exit</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">);</span>
<span class="Extracts-plain-syntax">    }</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">return</span><span class="Extracts-plain-syntax">             (</span><span class="Extracts-identifier-syntax">i7word_t</span><span class="Extracts-plain-syntax">) </span><span class="Extracts-identifier-syntax">data</span><span class="Extracts-plain-syntax">[</span><span class="Extracts-identifier-syntax">byte_position</span><span class="Extracts-plain-syntax"> + </span><span class="Extracts-constant-syntax">3</span><span class="Extracts-plain-syntax">]  +</span>
<span class="Extracts-plain-syntax">                </span><span class="Extracts-constant-syntax">0</span><span class="Extracts-identifier-syntax">x100U</span><span class="Extracts-plain-syntax">*((</span><span class="Extracts-identifier-syntax">i7word_t</span><span class="Extracts-plain-syntax">) </span><span class="Extracts-identifier-syntax">data</span><span class="Extracts-plain-syntax">[</span><span class="Extracts-identifier-syntax">byte_position</span><span class="Extracts-plain-syntax"> + </span><span class="Extracts-constant-syntax">2</span><span class="Extracts-plain-syntax">]) +</span>
<span class="Extracts-plain-syntax">              </span><span class="Extracts-constant-syntax">0</span><span class="Extracts-identifier-syntax">x10000U</span><span class="Extracts-plain-syntax">*((</span><span class="Extracts-identifier-syntax">i7word_t</span><span class="Extracts-plain-syntax">) </span><span class="Extracts-identifier-syntax">data</span><span class="Extracts-plain-syntax">[</span><span class="Extracts-identifier-syntax">byte_position</span><span class="Extracts-plain-syntax"> + </span><span class="Extracts-constant-syntax">1</span><span class="Extracts-plain-syntax">]) +</span>
<span class="Extracts-plain-syntax">            </span><span class="Extracts-constant-syntax">0</span><span class="Extracts-identifier-syntax">x1000000U</span><span class="Extracts-plain-syntax">*((</span><span class="Extracts-identifier-syntax">i7word_t</span><span class="Extracts-plain-syntax">) </span><span class="Extracts-identifier-syntax">data</span><span class="Extracts-plain-syntax">[</span><span class="Extracts-identifier-syntax">byte_position</span><span class="Extracts-plain-syntax"> + </span><span class="Extracts-constant-syntax">0</span><span class="Extracts-plain-syntax">]);</span>
<span class="Extracts-plain-syntax">}</span>
</pre>
<ul class="endnotetexts"><li>This is part of the extract file inform7_clib.c.</li></ul>
<p class="commentary firstcommentary"><a id="SP10" class="paragraph-anchor"></a><b>&#167;10. </b>Writing values is again easy for bytes, but harder for words since they must
be broken up into bytes written in sequence.
</p>

<p class="commentary">Note that we make use of macros and not functions so that it is possible to
express the fragments of a packed word in constant context: this is essential
for our array initialisations.
</p>

<p class="commentary">Note that short words do not need to be written.
</p>

<pre class="Extracts-displayed-code all-displayed-code code-font">
<span class="Extracts-plain-syntax">#</span><span class="Extracts-identifier-syntax">define</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">I7BYTE_0</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">V</span><span class="Extracts-plain-syntax">) ((</span><span class="Extracts-identifier-syntax">V</span><span class="Extracts-plain-syntax"> &amp; </span><span class="Extracts-constant-syntax">0</span><span class="Extracts-identifier-syntax">xFF000000</span><span class="Extracts-plain-syntax">) &gt;&gt; </span><span class="Extracts-constant-syntax">24</span><span class="Extracts-plain-syntax">)</span>
<span class="Extracts-plain-syntax">#</span><span class="Extracts-identifier-syntax">define</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">I7BYTE_1</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">V</span><span class="Extracts-plain-syntax">) ((</span><span class="Extracts-identifier-syntax">V</span><span class="Extracts-plain-syntax"> &amp; </span><span class="Extracts-constant-syntax">0</span><span class="Extracts-identifier-syntax">x00FF0000</span><span class="Extracts-plain-syntax">) &gt;&gt; </span><span class="Extracts-constant-syntax">16</span><span class="Extracts-plain-syntax">)</span>
<span class="Extracts-plain-syntax">#</span><span class="Extracts-identifier-syntax">define</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">I7BYTE_2</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">V</span><span class="Extracts-plain-syntax">) ((</span><span class="Extracts-identifier-syntax">V</span><span class="Extracts-plain-syntax"> &amp; </span><span class="Extracts-constant-syntax">0</span><span class="Extracts-identifier-syntax">x0000FF00</span><span class="Extracts-plain-syntax">) &gt;&gt; </span><span class="Extracts-constant-syntax">8</span><span class="Extracts-plain-syntax">)</span>
<span class="Extracts-plain-syntax">#</span><span class="Extracts-identifier-syntax">define</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">I7BYTE_3</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">V</span><span class="Extracts-plain-syntax">)  (</span><span class="Extracts-identifier-syntax">V</span><span class="Extracts-plain-syntax"> &amp; </span><span class="Extracts-constant-syntax">0</span><span class="Extracts-identifier-syntax">x000000FF</span><span class="Extracts-plain-syntax">)</span>

<span class="Extracts-identifier-syntax">void</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_write_byte</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">i7process_t</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">i7word_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">address</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">i7byte_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">new_val</span><span class="Extracts-plain-syntax">);</span>
<span class="Extracts-identifier-syntax">void</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_write_word</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">i7process_t</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">i7word_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">address</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">i7word_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">array_index</span><span class="Extracts-plain-syntax">,</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">i7word_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">new_val</span><span class="Extracts-plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This is part of the extract file inform7_clib.h.</li></ul>
<pre class="Extracts-displayed-code all-displayed-code code-font">
<span class="Extracts-identifier-syntax">void</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_write_byte</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">i7process_t</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">i7word_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">address</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">i7byte_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">new_val</span><span class="Extracts-plain-syntax">) {</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">state</span><span class="Extracts-plain-syntax">.</span><span class="Extracts-identifier-syntax">memory</span><span class="Extracts-plain-syntax">[</span><span class="Extracts-identifier-syntax">address</span><span class="Extracts-plain-syntax">] = </span><span class="Extracts-identifier-syntax">new_val</span><span class="Extracts-plain-syntax">;</span>
<span class="Extracts-plain-syntax">}</span>

<span class="Extracts-identifier-syntax">void</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_write_word</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">i7process_t</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">i7word_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">address</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">i7word_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">array_index</span><span class="Extracts-plain-syntax">,</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">i7word_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">new_val</span><span class="Extracts-plain-syntax">) {</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">int</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">byte_position</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">address</span><span class="Extracts-plain-syntax"> + </span><span class="Extracts-constant-syntax">4</span><span class="Extracts-plain-syntax">*</span><span class="Extracts-identifier-syntax">array_index</span><span class="Extracts-plain-syntax">;</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">if</span><span class="Extracts-plain-syntax"> ((</span><span class="Extracts-identifier-syntax">byte_position</span><span class="Extracts-plain-syntax"> &lt; </span><span class="Extracts-constant-syntax">0</span><span class="Extracts-plain-syntax">) || (</span><span class="Extracts-identifier-syntax">byte_position</span><span class="Extracts-plain-syntax"> &gt;= </span><span class="Extracts-identifier-syntax">i7_static_himem</span><span class="Extracts-plain-syntax">)) {</span>
<span class="Extracts-plain-syntax">        </span><span class="Extracts-identifier-syntax">printf</span><span class="Extracts-plain-syntax">("</span><span class="Extracts-identifier-syntax">Memory</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">access</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">out</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">of</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">range</span><span class="Extracts-plain-syntax">: %</span><span class="Extracts-identifier-syntax">d</span><span class="Extracts-plain-syntax">\</span><span class="Extracts-identifier-syntax">n</span><span class="Extracts-plain-syntax">", </span><span class="Extracts-identifier-syntax">byte_position</span><span class="Extracts-plain-syntax">);</span>
<span class="Extracts-plain-syntax">        </span><span class="Extracts-identifier-syntax">i7_fatal_exit</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">);</span>
<span class="Extracts-plain-syntax">    }</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">state</span><span class="Extracts-plain-syntax">.</span><span class="Extracts-identifier-syntax">memory</span><span class="Extracts-plain-syntax">[</span><span class="Extracts-identifier-syntax">byte_position</span><span class="Extracts-plain-syntax">]   = </span><span class="Extracts-identifier-syntax">I7BYTE_0</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">new_val</span><span class="Extracts-plain-syntax">);</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">state</span><span class="Extracts-plain-syntax">.</span><span class="Extracts-identifier-syntax">memory</span><span class="Extracts-plain-syntax">[</span><span class="Extracts-identifier-syntax">byte_position</span><span class="Extracts-plain-syntax">+1] = </span><span class="Extracts-identifier-syntax">I7BYTE_1</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">new_val</span><span class="Extracts-plain-syntax">);</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">state</span><span class="Extracts-plain-syntax">.</span><span class="Extracts-identifier-syntax">memory</span><span class="Extracts-plain-syntax">[</span><span class="Extracts-identifier-syntax">byte_position</span><span class="Extracts-plain-syntax">+2] = </span><span class="Extracts-identifier-syntax">I7BYTE_2</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">new_val</span><span class="Extracts-plain-syntax">);</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">state</span><span class="Extracts-plain-syntax">.</span><span class="Extracts-identifier-syntax">memory</span><span class="Extracts-plain-syntax">[</span><span class="Extracts-identifier-syntax">byte_position</span><span class="Extracts-plain-syntax">+3] = </span><span class="Extracts-identifier-syntax">I7BYTE_3</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">new_val</span><span class="Extracts-plain-syntax">);</span>
<span class="Extracts-plain-syntax">}</span>
</pre>
<ul class="endnotetexts"><li>This is part of the extract file inform7_clib.c.</li></ul>
<p class="commentary firstcommentary"><a id="SP11" class="paragraph-anchor"></a><b>&#167;11. </b></p>

<pre class="displayed-code all-displayed-code code-font">
<span class="reserved-syntax">void</span><span class="plain-syntax"> </span><span class="function-syntax">CMemoryModel::word_to_byte</span><button class="popup" onclick="togglePopup('usagePopup9')"><span class="comment-syntax">?</span><span class="popuptext" id="usagePopup9">Usage of <span class="code-font"><span class="function-syntax">CMemoryModel::word_to_byte</span></span>:<br/><a href="5-cmm.html#SP1">&#167;1</a></span></button><span class="plain-syntax">(</span><span class="reserved-syntax">code_generator</span><span class="plain-syntax"> *</span><span class="identifier-syntax">gtr</span><span class="plain-syntax">, </span><span class="reserved-syntax">code_generation</span><span class="plain-syntax"> *</span><span class="identifier-syntax">gen</span><span class="plain-syntax">,</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">OUTPUT_STREAM</span><span class="plain-syntax">, </span><span class="identifier-syntax">text_stream</span><span class="plain-syntax"> *</span><span class="identifier-syntax">val</span><span class="plain-syntax">, </span><span class="reserved-syntax">int</span><span class="plain-syntax"> </span><span class="identifier-syntax">b</span><span class="plain-syntax">) {</span>
<span class="plain-syntax">    </span><span class="identifier-syntax">WRITE</span><span class="plain-syntax">(</span><span class="string-syntax">"I7BYTE_%d(%S)"</span><span class="plain-syntax">, </span><span class="identifier-syntax">b</span><span class="plain-syntax">, </span><span class="identifier-syntax">val</span><span class="plain-syntax">);</span>
<span class="plain-syntax">}</span>
</pre>
<p class="commentary firstcommentary"><a id="SP12" class="paragraph-anchor"></a><b>&#167;12. </b>The seven primitive operations on storage need to be implemented for byte
and word lookups by the following pair of functions. Note that if <span class="extract"><span class="extract-syntax">way</span></span> is
<span class="extract"><span class="extract-syntax">i7_lvalue_SET</span></span> then <span class="extract"><span class="extract-syntax">i7_change_byte</span></span> is equivalent to <span class="extract"><span class="extract-syntax">i7_write_byte</span></span> and
<span class="extract"><span class="extract-syntax">i7_change_word</span></span> to <span class="extract"><span class="extract-syntax">i7_write_word</span></span>, except that they return the value as set.
</p>

<pre class="Extracts-displayed-code all-displayed-code code-font">
<span class="Extracts-identifier-syntax">i7byte_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_change_byte</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">i7process_t</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">i7word_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">address</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">i7byte_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">new_val</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">int</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">way</span><span class="Extracts-plain-syntax">);</span>
<span class="Extracts-identifier-syntax">i7word_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_change_word</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">i7process_t</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">i7word_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">array_address</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">i7word_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">array_index</span><span class="Extracts-plain-syntax">,</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">i7word_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">new_val</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">int</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">way</span><span class="Extracts-plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This is part of the extract file inform7_clib.h.</li></ul>
<pre class="Extracts-displayed-code all-displayed-code code-font">
<span class="Extracts-identifier-syntax">i7byte_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_change_byte</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">i7process_t</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">i7word_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">address</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">i7byte_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">new_val</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">int</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">way</span><span class="Extracts-plain-syntax">) {</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">i7byte_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">old_val</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">i7_read_byte</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">address</span><span class="Extracts-plain-syntax">);</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">i7byte_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">return_val</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">new_val</span><span class="Extracts-plain-syntax">;</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">switch</span><span class="Extracts-plain-syntax"> (</span><span class="Extracts-identifier-syntax">way</span><span class="Extracts-plain-syntax">) {</span>
<span class="Extracts-plain-syntax">        </span><span class="Extracts-identifier-syntax">case</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_lvalue_PREDEC</span><span class="Extracts-plain-syntax">:   </span><span class="Extracts-identifier-syntax">return_val</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">old_val</span><span class="Extracts-plain-syntax">-1;   </span><span class="Extracts-identifier-syntax">new_val</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">old_val</span><span class="Extracts-plain-syntax">-1; </span><span class="Extracts-identifier-syntax">break</span><span class="Extracts-plain-syntax">;</span>
<span class="Extracts-plain-syntax">        </span><span class="Extracts-identifier-syntax">case</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_lvalue_POSTDEC</span><span class="Extracts-plain-syntax">:  </span><span class="Extracts-identifier-syntax">return_val</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">old_val</span><span class="Extracts-plain-syntax">; </span><span class="Extracts-identifier-syntax">new_val</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">old_val</span><span class="Extracts-plain-syntax">-1; </span><span class="Extracts-identifier-syntax">break</span><span class="Extracts-plain-syntax">;</span>
<span class="Extracts-plain-syntax">        </span><span class="Extracts-identifier-syntax">case</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_lvalue_PREINC</span><span class="Extracts-plain-syntax">:   </span><span class="Extracts-identifier-syntax">return_val</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">old_val</span><span class="Extracts-plain-syntax">+1;   </span><span class="Extracts-identifier-syntax">new_val</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">old_val</span><span class="Extracts-plain-syntax">+1; </span><span class="Extracts-identifier-syntax">break</span><span class="Extracts-plain-syntax">;</span>
<span class="Extracts-plain-syntax">        </span><span class="Extracts-identifier-syntax">case</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_lvalue_POSTINC</span><span class="Extracts-plain-syntax">:  </span><span class="Extracts-identifier-syntax">return_val</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">old_val</span><span class="Extracts-plain-syntax">; </span><span class="Extracts-identifier-syntax">new_val</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">old_val</span><span class="Extracts-plain-syntax">+1; </span><span class="Extracts-identifier-syntax">break</span><span class="Extracts-plain-syntax">;</span>
<span class="Extracts-plain-syntax">        </span><span class="Extracts-identifier-syntax">case</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_lvalue_SETBIT</span><span class="Extracts-plain-syntax">:   </span><span class="Extracts-identifier-syntax">new_val</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">old_val</span><span class="Extracts-plain-syntax"> | </span><span class="Extracts-identifier-syntax">new_val</span><span class="Extracts-plain-syntax">; </span><span class="Extracts-identifier-syntax">return_val</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">new_val</span><span class="Extracts-plain-syntax">; </span><span class="Extracts-identifier-syntax">break</span><span class="Extracts-plain-syntax">;</span>
<span class="Extracts-plain-syntax">        </span><span class="Extracts-identifier-syntax">case</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_lvalue_CLEARBIT</span><span class="Extracts-plain-syntax">: </span><span class="Extracts-identifier-syntax">new_val</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">old_val</span><span class="Extracts-plain-syntax"> &amp;(~</span><span class="Extracts-identifier-syntax">new_val</span><span class="Extracts-plain-syntax">); </span><span class="Extracts-identifier-syntax">return_val</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">new_val</span><span class="Extracts-plain-syntax">; </span><span class="Extracts-identifier-syntax">break</span><span class="Extracts-plain-syntax">;</span>
<span class="Extracts-plain-syntax">    }</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">i7_write_byte</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">address</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">new_val</span><span class="Extracts-plain-syntax">);</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">return</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">return_val</span><span class="Extracts-plain-syntax">;</span>
<span class="Extracts-plain-syntax">}</span>

<span class="Extracts-identifier-syntax">i7word_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_change_word</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">i7process_t</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">i7word_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">array_address</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">i7word_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">array_index</span><span class="Extracts-plain-syntax">,</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">i7word_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">new_val</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">int</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">way</span><span class="Extracts-plain-syntax">) {</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">i7byte_t</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">data</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">state</span><span class="Extracts-plain-syntax">.</span><span class="Extracts-identifier-syntax">memory</span><span class="Extracts-plain-syntax">;</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">i7word_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">old_val</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">i7_read_word</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">array_address</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">array_index</span><span class="Extracts-plain-syntax">);</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">i7word_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">return_val</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">new_val</span><span class="Extracts-plain-syntax">;</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">switch</span><span class="Extracts-plain-syntax"> (</span><span class="Extracts-identifier-syntax">way</span><span class="Extracts-plain-syntax">) {</span>
<span class="Extracts-plain-syntax">        </span><span class="Extracts-identifier-syntax">case</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_lvalue_PREDEC</span><span class="Extracts-plain-syntax">:   </span><span class="Extracts-identifier-syntax">return_val</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">old_val</span><span class="Extracts-plain-syntax">-1;   </span><span class="Extracts-identifier-syntax">new_val</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">old_val</span><span class="Extracts-plain-syntax">-1; </span><span class="Extracts-identifier-syntax">break</span><span class="Extracts-plain-syntax">;</span>
<span class="Extracts-plain-syntax">        </span><span class="Extracts-identifier-syntax">case</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_lvalue_POSTDEC</span><span class="Extracts-plain-syntax">:  </span><span class="Extracts-identifier-syntax">return_val</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">old_val</span><span class="Extracts-plain-syntax">; </span><span class="Extracts-identifier-syntax">new_val</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">old_val</span><span class="Extracts-plain-syntax">-1; </span><span class="Extracts-identifier-syntax">break</span><span class="Extracts-plain-syntax">;</span>
<span class="Extracts-plain-syntax">        </span><span class="Extracts-identifier-syntax">case</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_lvalue_PREINC</span><span class="Extracts-plain-syntax">:   </span><span class="Extracts-identifier-syntax">return_val</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">old_val</span><span class="Extracts-plain-syntax">+1;   </span><span class="Extracts-identifier-syntax">new_val</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">old_val</span><span class="Extracts-plain-syntax">+1; </span><span class="Extracts-identifier-syntax">break</span><span class="Extracts-plain-syntax">;</span>
<span class="Extracts-plain-syntax">        </span><span class="Extracts-identifier-syntax">case</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_lvalue_POSTINC</span><span class="Extracts-plain-syntax">:  </span><span class="Extracts-identifier-syntax">return_val</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">old_val</span><span class="Extracts-plain-syntax">; </span><span class="Extracts-identifier-syntax">new_val</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">old_val</span><span class="Extracts-plain-syntax">+1; </span><span class="Extracts-identifier-syntax">break</span><span class="Extracts-plain-syntax">;</span>
<span class="Extracts-plain-syntax">        </span><span class="Extracts-identifier-syntax">case</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_lvalue_SETBIT</span><span class="Extracts-plain-syntax">:   </span><span class="Extracts-identifier-syntax">new_val</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">old_val</span><span class="Extracts-plain-syntax"> | </span><span class="Extracts-identifier-syntax">new_val</span><span class="Extracts-plain-syntax">; </span><span class="Extracts-identifier-syntax">return_val</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">new_val</span><span class="Extracts-plain-syntax">; </span><span class="Extracts-identifier-syntax">break</span><span class="Extracts-plain-syntax">;</span>
<span class="Extracts-plain-syntax">        </span><span class="Extracts-identifier-syntax">case</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_lvalue_CLEARBIT</span><span class="Extracts-plain-syntax">: </span><span class="Extracts-identifier-syntax">new_val</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">old_val</span><span class="Extracts-plain-syntax"> &amp;(~</span><span class="Extracts-identifier-syntax">new_val</span><span class="Extracts-plain-syntax">); </span><span class="Extracts-identifier-syntax">return_val</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">new_val</span><span class="Extracts-plain-syntax">; </span><span class="Extracts-identifier-syntax">break</span><span class="Extracts-plain-syntax">;</span>
<span class="Extracts-plain-syntax">    }</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">i7_write_word</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">array_address</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">array_index</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">new_val</span><span class="Extracts-plain-syntax">);</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">return</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">return_val</span><span class="Extracts-plain-syntax">;</span>
<span class="Extracts-plain-syntax">}</span>
</pre>
<ul class="endnotetexts"><li>This is part of the extract file inform7_clib.c.</li></ul>
<p class="commentary firstcommentary"><a id="SP13" class="paragraph-anchor"></a><b>&#167;13. </b>The stack is very simple; it can be pushed or pulled, but there's otherwise
no access to it.
</p>

<pre class="Extracts-displayed-code all-displayed-code code-font">
<span class="Extracts-identifier-syntax">void</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_debug_stack</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">char</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">N</span><span class="Extracts-plain-syntax">);</span>
<span class="Extracts-identifier-syntax">i7word_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_pull</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">i7process_t</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">);</span>
<span class="Extracts-identifier-syntax">void</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_push</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">i7process_t</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">i7word_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">x</span><span class="Extracts-plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This is part of the extract file inform7_clib.h.</li></ul>
<pre class="Extracts-displayed-code all-displayed-code code-font">
<span class="Extracts-identifier-syntax">void</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_debug_stack</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">char</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">N</span><span class="Extracts-plain-syntax">) {</span>
<span class="Extracts-plain-syntax">    #</span><span class="Extracts-identifier-syntax">ifdef</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">I7_LOG_STACK_STATE</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">printf</span><span class="Extracts-plain-syntax">("</span><span class="Extracts-identifier-syntax">Called</span><span class="Extracts-plain-syntax"> %</span><span class="Extracts-identifier-syntax">s</span><span class="Extracts-plain-syntax">: </span><span class="Extracts-identifier-syntax">stack</span><span class="Extracts-plain-syntax"> %</span><span class="Extracts-identifier-syntax">d</span><span class="Extracts-plain-syntax"> ", </span><span class="Extracts-identifier-syntax">N</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">state</span><span class="Extracts-plain-syntax">.</span><span class="Extracts-identifier-syntax">stack_pointer</span><span class="Extracts-plain-syntax">);</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">for</span><span class="Extracts-plain-syntax"> (</span><span class="Extracts-identifier-syntax">int</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i</span><span class="Extracts-plain-syntax">=0; </span><span class="Extracts-identifier-syntax">i</span><span class="Extracts-plain-syntax">&lt;</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">state</span><span class="Extracts-plain-syntax">.</span><span class="Extracts-identifier-syntax">stack_pointer</span><span class="Extracts-plain-syntax">; </span><span class="Extracts-identifier-syntax">i</span><span class="Extracts-plain-syntax">++)</span>
<span class="Extracts-plain-syntax">        </span><span class="Extracts-identifier-syntax">printf</span><span class="Extracts-plain-syntax">("%</span><span class="Extracts-identifier-syntax">d</span><span class="Extracts-plain-syntax"> -&gt; ", </span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">state</span><span class="Extracts-plain-syntax">.</span><span class="Extracts-identifier-syntax">stack</span><span class="Extracts-plain-syntax">[</span><span class="Extracts-identifier-syntax">i</span><span class="Extracts-plain-syntax">]);</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">printf</span><span class="Extracts-plain-syntax">("\</span><span class="Extracts-identifier-syntax">n</span><span class="Extracts-plain-syntax">");</span>
<span class="Extracts-plain-syntax">    #</span><span class="Extracts-identifier-syntax">endif</span>
<span class="Extracts-plain-syntax">}</span>

<span class="Extracts-identifier-syntax">i7word_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_pull</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">i7process_t</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">) {</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">if</span><span class="Extracts-plain-syntax"> (</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">state</span><span class="Extracts-plain-syntax">.</span><span class="Extracts-identifier-syntax">stack_pointer</span><span class="Extracts-plain-syntax"> &lt;= </span><span class="Extracts-constant-syntax">0</span><span class="Extracts-plain-syntax">) {</span>
<span class="Extracts-plain-syntax">        </span><span class="Extracts-identifier-syntax">printf</span><span class="Extracts-plain-syntax">("</span><span class="Extracts-identifier-syntax">Stack</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">underflow</span><span class="Extracts-plain-syntax">\</span><span class="Extracts-identifier-syntax">n</span><span class="Extracts-plain-syntax">");</span>
<span class="Extracts-plain-syntax">        </span><span class="Extracts-identifier-syntax">i7_fatal_exit</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">);</span>
<span class="Extracts-plain-syntax">    }</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">return</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">state</span><span class="Extracts-plain-syntax">.</span><span class="Extracts-identifier-syntax">stack</span><span class="Extracts-plain-syntax">[--(</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">state</span><span class="Extracts-plain-syntax">.</span><span class="Extracts-identifier-syntax">stack_pointer</span><span class="Extracts-plain-syntax">)];</span>
<span class="Extracts-plain-syntax">}</span>

<span class="Extracts-identifier-syntax">void</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_push</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">i7process_t</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">i7word_t</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">x</span><span class="Extracts-plain-syntax">) {</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">if</span><span class="Extracts-plain-syntax"> (</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">state</span><span class="Extracts-plain-syntax">.</span><span class="Extracts-identifier-syntax">stack_pointer</span><span class="Extracts-plain-syntax"> &gt;= </span><span class="Extracts-identifier-syntax">I7_ASM_STACK_CAPACITY</span><span class="Extracts-plain-syntax">) {</span>
<span class="Extracts-plain-syntax">        </span><span class="Extracts-identifier-syntax">printf</span><span class="Extracts-plain-syntax">("</span><span class="Extracts-identifier-syntax">Stack</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">overflow</span><span class="Extracts-plain-syntax">\</span><span class="Extracts-identifier-syntax">n</span><span class="Extracts-plain-syntax">");</span>
<span class="Extracts-plain-syntax">        </span><span class="Extracts-identifier-syntax">i7_fatal_exit</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">);</span>
<span class="Extracts-plain-syntax">    }</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">state</span><span class="Extracts-plain-syntax">.</span><span class="Extracts-identifier-syntax">stack</span><span class="Extracts-plain-syntax">[</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">state</span><span class="Extracts-plain-syntax">.</span><span class="Extracts-identifier-syntax">stack_pointer</span><span class="Extracts-plain-syntax">++] = </span><span class="Extracts-identifier-syntax">x</span><span class="Extracts-plain-syntax">;</span>
<span class="Extracts-plain-syntax">}</span>
</pre>
<ul class="endnotetexts"><li>This is part of the extract file inform7_clib.c.</li></ul>
<p class="commentary firstcommentary"><a id="SP14" class="paragraph-anchor"></a><b>&#167;14. </b>When processes are running, they take periodic "snapshots" of their states
so that these can if necessary be returned to. (For IF works, this is how the
UNDO command works; snapshots are taken once each turn.)
</p>

<p class="commentary">Taking a snapshot, or restoring the state from an existing snapshot, inevitably
means making a copy of state data. This has to be a deep copy, because the
<span class="extract"><span class="Extracts-extract-syntax">i7state_t</span></span> structure is really just a collection of pointers to arrays in
memory; copying only the pointers would not be good enough.
</p>

<p class="commentary">For the same reason, an <span class="extract"><span class="Extracts-extract-syntax">i7state_t</span></span> cannot simply be discarded without causing
a memory leak, so we provide a destructor function.
</p>

<pre class="Extracts-displayed-code all-displayed-code code-font">
<span class="Extracts-identifier-syntax">void</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_copy_state</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">i7process_t</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">i7state_t</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">to</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">i7state_t</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">from</span><span class="Extracts-plain-syntax">);</span>
<span class="Extracts-identifier-syntax">void</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_destroy_state</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">i7process_t</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">i7state_t</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">s</span><span class="Extracts-plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This is part of the extract file inform7_clib.h.</li></ul>
<pre class="Extracts-displayed-code all-displayed-code code-font">
<span class="Extracts-identifier-syntax">void</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_copy_state</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">i7process_t</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">i7state_t</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">to</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">i7state_t</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">from</span><span class="Extracts-plain-syntax">) {</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">to</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">himem</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">from</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">himem</span><span class="Extracts-plain-syntax">;</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">to</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">memory</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">i7_calloc</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">i7_static_himem</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">sizeof</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">i7byte_t</span><span class="Extracts-plain-syntax">));</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">for</span><span class="Extracts-plain-syntax"> (</span><span class="Extracts-identifier-syntax">int</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i</span><span class="Extracts-plain-syntax">=0; </span><span class="Extracts-identifier-syntax">i</span><span class="Extracts-plain-syntax">&lt;</span><span class="Extracts-identifier-syntax">i7_static_himem</span><span class="Extracts-plain-syntax">; </span><span class="Extracts-identifier-syntax">i</span><span class="Extracts-plain-syntax">++) </span><span class="Extracts-identifier-syntax">to</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">memory</span><span class="Extracts-plain-syntax">[</span><span class="Extracts-identifier-syntax">i</span><span class="Extracts-plain-syntax">] = </span><span class="Extracts-identifier-syntax">from</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">memory</span><span class="Extracts-plain-syntax">[</span><span class="Extracts-identifier-syntax">i</span><span class="Extracts-plain-syntax">];</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">for</span><span class="Extracts-plain-syntax"> (</span><span class="Extracts-identifier-syntax">int</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i</span><span class="Extracts-plain-syntax">=0; </span><span class="Extracts-identifier-syntax">i</span><span class="Extracts-plain-syntax">&lt;</span><span class="Extracts-identifier-syntax">I7_TMP_STORAGE_CAPACITY</span><span class="Extracts-plain-syntax">; </span><span class="Extracts-identifier-syntax">i</span><span class="Extracts-plain-syntax">++) </span><span class="Extracts-identifier-syntax">to</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">tmp</span><span class="Extracts-plain-syntax">[</span><span class="Extracts-identifier-syntax">i</span><span class="Extracts-plain-syntax">] = </span><span class="Extracts-identifier-syntax">from</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">tmp</span><span class="Extracts-plain-syntax">[</span><span class="Extracts-identifier-syntax">i</span><span class="Extracts-plain-syntax">];</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">to</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">stack_pointer</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">from</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">stack_pointer</span><span class="Extracts-plain-syntax">;</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">for</span><span class="Extracts-plain-syntax"> (</span><span class="Extracts-identifier-syntax">int</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i</span><span class="Extracts-plain-syntax">=0; </span><span class="Extracts-identifier-syntax">i</span><span class="Extracts-plain-syntax">&lt;</span><span class="Extracts-identifier-syntax">from</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">stack_pointer</span><span class="Extracts-plain-syntax">; </span><span class="Extracts-identifier-syntax">i</span><span class="Extracts-plain-syntax">++) </span><span class="Extracts-identifier-syntax">to</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">stack</span><span class="Extracts-plain-syntax">[</span><span class="Extracts-identifier-syntax">i</span><span class="Extracts-plain-syntax">] = </span><span class="Extracts-identifier-syntax">from</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">stack</span><span class="Extracts-plain-syntax">[</span><span class="Extracts-identifier-syntax">i</span><span class="Extracts-plain-syntax">];</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">to</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">object_tree_parent</span><span class="Extracts-plain-syntax">  = </span><span class="Extracts-identifier-syntax">i7_calloc</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">i7_max_objects</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">sizeof</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">i7word_t</span><span class="Extracts-plain-syntax">));</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">to</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">object_tree_child</span><span class="Extracts-plain-syntax">   = </span><span class="Extracts-identifier-syntax">i7_calloc</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">i7_max_objects</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">sizeof</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">i7word_t</span><span class="Extracts-plain-syntax">));</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">to</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">object_tree_sibling</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">i7_calloc</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">i7_max_objects</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">sizeof</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">i7word_t</span><span class="Extracts-plain-syntax">));</span>

<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">for</span><span class="Extracts-plain-syntax"> (</span><span class="Extracts-identifier-syntax">int</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i</span><span class="Extracts-plain-syntax">=0; </span><span class="Extracts-identifier-syntax">i</span><span class="Extracts-plain-syntax">&lt;</span><span class="Extracts-identifier-syntax">i7_max_objects</span><span class="Extracts-plain-syntax">; </span><span class="Extracts-identifier-syntax">i</span><span class="Extracts-plain-syntax">++) {</span>
<span class="Extracts-plain-syntax">        </span><span class="Extracts-identifier-syntax">to</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">object_tree_parent</span><span class="Extracts-plain-syntax">[</span><span class="Extracts-identifier-syntax">i</span><span class="Extracts-plain-syntax">] = </span><span class="Extracts-identifier-syntax">from</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">object_tree_parent</span><span class="Extracts-plain-syntax">[</span><span class="Extracts-identifier-syntax">i</span><span class="Extracts-plain-syntax">];</span>
<span class="Extracts-plain-syntax">        </span><span class="Extracts-identifier-syntax">to</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">object_tree_child</span><span class="Extracts-plain-syntax">[</span><span class="Extracts-identifier-syntax">i</span><span class="Extracts-plain-syntax">] = </span><span class="Extracts-identifier-syntax">from</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">object_tree_child</span><span class="Extracts-plain-syntax">[</span><span class="Extracts-identifier-syntax">i</span><span class="Extracts-plain-syntax">];</span>
<span class="Extracts-plain-syntax">        </span><span class="Extracts-identifier-syntax">to</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">object_tree_sibling</span><span class="Extracts-plain-syntax">[</span><span class="Extracts-identifier-syntax">i</span><span class="Extracts-plain-syntax">] = </span><span class="Extracts-identifier-syntax">from</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">object_tree_sibling</span><span class="Extracts-plain-syntax">[</span><span class="Extracts-identifier-syntax">i</span><span class="Extracts-plain-syntax">];</span>
<span class="Extracts-plain-syntax">    }</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">to</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">variables</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">i7_calloc</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">i7_no_variables</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">sizeof</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">i7word_t</span><span class="Extracts-plain-syntax">));</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">for</span><span class="Extracts-plain-syntax"> (</span><span class="Extracts-identifier-syntax">int</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i</span><span class="Extracts-plain-syntax">=0; </span><span class="Extracts-identifier-syntax">i</span><span class="Extracts-plain-syntax">&lt;</span><span class="Extracts-identifier-syntax">i7_no_variables</span><span class="Extracts-plain-syntax">; </span><span class="Extracts-identifier-syntax">i</span><span class="Extracts-plain-syntax">++) </span><span class="Extracts-identifier-syntax">to</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">variables</span><span class="Extracts-plain-syntax">[</span><span class="Extracts-identifier-syntax">i</span><span class="Extracts-plain-syntax">] = </span><span class="Extracts-identifier-syntax">from</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">variables</span><span class="Extracts-plain-syntax">[</span><span class="Extracts-identifier-syntax">i</span><span class="Extracts-plain-syntax">];</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">to</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">current_output_stream_ID</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">from</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">current_output_stream_ID</span><span class="Extracts-plain-syntax">;</span>
<span class="Extracts-plain-syntax">}</span>

<span class="Extracts-identifier-syntax">void</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_destroy_state</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">i7process_t</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">i7state_t</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">s</span><span class="Extracts-plain-syntax">) {</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">free</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">s</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">memory</span><span class="Extracts-plain-syntax">);</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">s</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">himem</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-constant-syntax">0</span><span class="Extracts-plain-syntax">;</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">s</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">stack_pointer</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-constant-syntax">0</span><span class="Extracts-plain-syntax">;</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">free</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">s</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">object_tree_parent</span><span class="Extracts-plain-syntax">);</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">free</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">s</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">object_tree_child</span><span class="Extracts-plain-syntax">);</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">free</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">s</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">object_tree_sibling</span><span class="Extracts-plain-syntax">);</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">free</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">s</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">variables</span><span class="Extracts-plain-syntax">);</span>
<span class="Extracts-plain-syntax">}</span>
</pre>
<ul class="endnotetexts"><li>This is part of the extract file inform7_clib.c.</li></ul>
<p class="commentary firstcommentary"><a id="SP15" class="paragraph-anchor"></a><b>&#167;15. </b>Destroying a snapshot is then a simple matter of destroying the state
stored inside it:
</p>

<pre class="Extracts-displayed-code all-displayed-code code-font">
<span class="Extracts-identifier-syntax">void</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_destroy_snapshot</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">i7process_t</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">i7snapshot_t</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">unwanted</span><span class="Extracts-plain-syntax">);</span>
<span class="Extracts-identifier-syntax">void</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_destroy_latest_snapshot</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">i7process_t</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This is part of the extract file inform7_clib.h.</li></ul>
<pre class="Extracts-displayed-code all-displayed-code code-font">
<span class="Extracts-identifier-syntax">void</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_destroy_snapshot</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">i7process_t</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">i7snapshot_t</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">unwanted</span><span class="Extracts-plain-syntax">) {</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">i7_destroy_state</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">, &amp;(</span><span class="Extracts-identifier-syntax">unwanted</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">then</span><span class="Extracts-plain-syntax">));</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">unwanted</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">valid</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-constant-syntax">0</span><span class="Extracts-plain-syntax">;</span>
<span class="Extracts-plain-syntax">}</span>

<span class="Extracts-identifier-syntax">void</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_destroy_latest_snapshot</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">i7process_t</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">) {</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">int</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">will_be</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">snapshot_pos</span><span class="Extracts-plain-syntax"> - </span><span class="Extracts-constant-syntax">1</span><span class="Extracts-plain-syntax">;</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">if</span><span class="Extracts-plain-syntax"> (</span><span class="Extracts-identifier-syntax">will_be</span><span class="Extracts-plain-syntax"> &lt; </span><span class="Extracts-constant-syntax">0</span><span class="Extracts-plain-syntax">) </span><span class="Extracts-identifier-syntax">will_be</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">I7_MAX_SNAPSHOTS</span><span class="Extracts-plain-syntax"> - </span><span class="Extracts-constant-syntax">1</span><span class="Extracts-plain-syntax">;</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">if</span><span class="Extracts-plain-syntax"> (</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">snapshots</span><span class="Extracts-plain-syntax">[</span><span class="Extracts-identifier-syntax">will_be</span><span class="Extracts-plain-syntax">].</span><span class="Extracts-identifier-syntax">valid</span><span class="Extracts-plain-syntax">)</span>
<span class="Extracts-plain-syntax">        </span><span class="Extracts-identifier-syntax">i7_destroy_snapshot</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">, &amp;(</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">snapshots</span><span class="Extracts-plain-syntax">[</span><span class="Extracts-identifier-syntax">will_be</span><span class="Extracts-plain-syntax">]));</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">snapshot_pos</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">will_be</span><span class="Extracts-plain-syntax">;</span>
<span class="Extracts-plain-syntax">}</span>
</pre>
<ul class="endnotetexts"><li>This is part of the extract file inform7_clib.c.</li></ul>
<p class="commentary firstcommentary"><a id="SP16" class="paragraph-anchor"></a><b>&#167;16. </b>To take a snapshot, we copy the process's current state in the next free
slot in the ring buffer of snapshots held by the process; the net effect is
that it stores the most recent <span class="extract"><span class="Extracts-extract-syntax">I7_MAX_SNAPSHOTS</span></span> snapshots, silently discarding
any older ones, but without leaking memory.
</p>

<pre class="Extracts-displayed-code all-displayed-code code-font">
<span class="Extracts-identifier-syntax">void</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_save_snapshot</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">i7process_t</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This is part of the extract file inform7_clib.h.</li></ul>
<pre class="Extracts-displayed-code all-displayed-code code-font">
<span class="Extracts-identifier-syntax">void</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_save_snapshot</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">i7process_t</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">) {</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">if</span><span class="Extracts-plain-syntax"> (</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">snapshots</span><span class="Extracts-plain-syntax">[</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">snapshot_pos</span><span class="Extracts-plain-syntax">].</span><span class="Extracts-identifier-syntax">valid</span><span class="Extracts-plain-syntax">)</span>
<span class="Extracts-plain-syntax">        </span><span class="Extracts-identifier-syntax">i7_destroy_snapshot</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">, &amp;(</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">snapshots</span><span class="Extracts-plain-syntax">[</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">snapshot_pos</span><span class="Extracts-plain-syntax">]));</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">snapshots</span><span class="Extracts-plain-syntax">[</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">snapshot_pos</span><span class="Extracts-plain-syntax">] = </span><span class="Extracts-identifier-syntax">i7_new_snapshot</span><span class="Extracts-plain-syntax">();</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">snapshots</span><span class="Extracts-plain-syntax">[</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">snapshot_pos</span><span class="Extracts-plain-syntax">].</span><span class="Extracts-identifier-syntax">valid</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-constant-syntax">1</span><span class="Extracts-plain-syntax">;</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">i7_copy_state</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">, &amp;(</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">snapshots</span><span class="Extracts-plain-syntax">[</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">snapshot_pos</span><span class="Extracts-plain-syntax">].</span><span class="Extracts-identifier-syntax">then</span><span class="Extracts-plain-syntax">), &amp;(</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">state</span><span class="Extracts-plain-syntax">));</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">int</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">was</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">snapshot_pos</span><span class="Extracts-plain-syntax">;</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">snapshot_pos</span><span class="Extracts-plain-syntax">++;</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">if</span><span class="Extracts-plain-syntax"> (</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">snapshot_pos</span><span class="Extracts-plain-syntax"> == </span><span class="Extracts-identifier-syntax">I7_MAX_SNAPSHOTS</span><span class="Extracts-plain-syntax">) </span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">snapshot_pos</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-constant-syntax">0</span><span class="Extracts-plain-syntax">;</span>
<span class="Extracts-plain-syntax">}</span>
</pre>
<ul class="endnotetexts"><li>This is part of the extract file inform7_clib.c.</li></ul>
<p class="commentary firstcommentary"><a id="SP17" class="paragraph-anchor"></a><b>&#167;17. </b>The function <span class="extract"><span class="Extracts-extract-syntax">i7_has_snapshot</span></span> tests whether the process has at least one
valid snapshot to revert to:
</p>

<pre class="Extracts-displayed-code all-displayed-code code-font">
<span class="Extracts-identifier-syntax">int</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_has_snapshot</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">i7process_t</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">);</span>
<span class="Extracts-identifier-syntax">void</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_restore_snapshot</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">i7process_t</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">);</span>
<span class="Extracts-identifier-syntax">void</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_restore_snapshot_from</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">i7process_t</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">, </span><span class="Extracts-identifier-syntax">i7snapshot_t</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">ss</span><span class="Extracts-plain-syntax">);</span>
</pre>
<ul class="endnotetexts"><li>This is part of the extract file inform7_clib.h.</li></ul>
<pre class="Extracts-displayed-code all-displayed-code code-font">
<span class="Extracts-identifier-syntax">int</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_has_snapshot</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">i7process_t</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">) {</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">int</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">will_be</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">snapshot_pos</span><span class="Extracts-plain-syntax"> - </span><span class="Extracts-constant-syntax">1</span><span class="Extracts-plain-syntax">;</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">if</span><span class="Extracts-plain-syntax"> (</span><span class="Extracts-identifier-syntax">will_be</span><span class="Extracts-plain-syntax"> &lt; </span><span class="Extracts-constant-syntax">0</span><span class="Extracts-plain-syntax">) </span><span class="Extracts-identifier-syntax">will_be</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">I7_MAX_SNAPSHOTS</span><span class="Extracts-plain-syntax"> - </span><span class="Extracts-constant-syntax">1</span><span class="Extracts-plain-syntax">;</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">return</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">snapshots</span><span class="Extracts-plain-syntax">[</span><span class="Extracts-identifier-syntax">will_be</span><span class="Extracts-plain-syntax">].</span><span class="Extracts-identifier-syntax">valid</span><span class="Extracts-plain-syntax">;</span>
<span class="Extracts-plain-syntax">}</span>
</pre>
<ul class="endnotetexts"><li>This is part of the extract file inform7_clib.c.</li></ul>
<p class="commentary">And <span class="extract"><span class="Extracts-extract-syntax">i7_restore_snapshot</span></span> restores the state of the process to that of the
most recent snapshot, winding backwards through the ring buffer, so that it's
then possible to restore again to go back another step, and so on:
</p>

<pre class="Extracts-displayed-code all-displayed-code code-font">
<span class="Extracts-identifier-syntax">void</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">i7_restore_snapshot</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">i7process_t</span><span class="Extracts-plain-syntax"> *</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">) {</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">int</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">will_be</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">snapshot_pos</span><span class="Extracts-plain-syntax"> - </span><span class="Extracts-constant-syntax">1</span><span class="Extracts-plain-syntax">;</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">if</span><span class="Extracts-plain-syntax"> (</span><span class="Extracts-identifier-syntax">will_be</span><span class="Extracts-plain-syntax"> &lt; </span><span class="Extracts-constant-syntax">0</span><span class="Extracts-plain-syntax">) </span><span class="Extracts-identifier-syntax">will_be</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">I7_MAX_SNAPSHOTS</span><span class="Extracts-plain-syntax"> - </span><span class="Extracts-constant-syntax">1</span><span class="Extracts-plain-syntax">;</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">if</span><span class="Extracts-plain-syntax"> (</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">snapshots</span><span class="Extracts-plain-syntax">[</span><span class="Extracts-identifier-syntax">will_be</span><span class="Extracts-plain-syntax">].</span><span class="Extracts-identifier-syntax">valid</span><span class="Extracts-plain-syntax"> == </span><span class="Extracts-constant-syntax">0</span><span class="Extracts-plain-syntax">) {</span>
<span class="Extracts-plain-syntax">        </span><span class="Extracts-identifier-syntax">printf</span><span class="Extracts-plain-syntax">("</span><span class="Extracts-identifier-syntax">Restore</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">impossible</span><span class="Extracts-plain-syntax">\</span><span class="Extracts-identifier-syntax">n</span><span class="Extracts-plain-syntax">");</span>
<span class="Extracts-plain-syntax">        </span><span class="Extracts-identifier-syntax">i7_fatal_exit</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">);</span>
<span class="Extracts-plain-syntax">    }</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">i7_destroy_state</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">, &amp;(</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">state</span><span class="Extracts-plain-syntax">));</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">i7_copy_state</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">, &amp;(</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">state</span><span class="Extracts-plain-syntax">), &amp;(</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">snapshots</span><span class="Extracts-plain-syntax">[</span><span class="Extracts-identifier-syntax">will_be</span><span class="Extracts-plain-syntax">].</span><span class="Extracts-identifier-syntax">then</span><span class="Extracts-plain-syntax">));</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">i7_destroy_snapshot</span><span class="Extracts-plain-syntax">(</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">, &amp;(</span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">snapshots</span><span class="Extracts-plain-syntax">[</span><span class="Extracts-identifier-syntax">will_be</span><span class="Extracts-plain-syntax">]));</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">int</span><span class="Extracts-plain-syntax"> </span><span class="Extracts-identifier-syntax">was</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">snapshot_pos</span><span class="Extracts-plain-syntax">;</span>
<span class="Extracts-plain-syntax">    </span><span class="Extracts-identifier-syntax">proc</span><span class="Extracts-plain-syntax">-&gt;</span><span class="Extracts-identifier-syntax">snapshot_pos</span><span class="Extracts-plain-syntax"> = </span><span class="Extracts-identifier-syntax">will_be</span><span class="Extracts-plain-syntax">;</span>
<span class="Extracts-plain-syntax">}</span>
</pre>
<ul class="endnotetexts"><li>This is part of the extract file inform7_clib.c.</li></ul>
<nav role="progress"><div class="progresscontainer">
    <ul class="progressbar"><li class="progressprev"><a href="5-cgv.html">&#10094;</a></li><li class="progresschapter"><a href="P-wtmd.html">P</a></li><li class="progresschapter"><a href="1-fm.html">1</a></li><li class="progresschapter"><a href="2-cg.html">2</a></li><li class="progresschapter"><a href="3-fti.html">3</a></li><li class="progresschapter"><a href="4-fi6.html">4</a></li><li class="progresscurrentchapter">5</li><li class="progresssection"><a href="5-fnc.html">fnc</a></li><li class="progresssection"><a href="5-cnm.html">cnm</a></li><li class="progresssection"><a href="5-crf.html">crf</a></li><li class="progresssection"><a href="5-cgv.html">cgv</a></li><li class="progresscurrent">cmm</li><li class="progresssection"><a href="5-cas.html">cas</a></li><li class="progresssection"><a href="5-car.html">car</a></li><li class="progresssection"><a href="5-cpc.html">cpc</a></li><li class="progresssection"><a href="5-ccn.html">ccn</a></li><li class="progresssection"><a href="5-clt.html">clt</a></li><li class="progresssection"><a href="5-com.html">com</a></li><li class="progresssection"><a href="5-cfm.html">cfm</a></li><li class="progresssection"><a href="5-cim.html">cim</a></li><li class="progresssection"><a href="5-cmn.html">cmn</a></li><li class="progresssection"><a href="5-cuf.html">cuf</a></li><li class="progressnext"><a href="5-cas.html">&#10095;</a></li></ul></div>
</nav><!-- End of weave -->

		</main>
	</body>
</html>

